

package com.xgit.iov.common.core.entity;

import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;

/**
 * @author lengleng
 * @date 2019/2/1
 * 扩展用户信息
 */
public class IovUser extends User {
	/**
	 * 用户ID
	 */
	@Getter
	private Long id;
	/**
	 * 部门ID
	 */
	@Getter
	private Long deptId;

	/**
	 * 租户ID
	 */
	@Getter
	private Long tenantId;

	public IovUser(Long id, Long deptId, String username, String password, Long tenantId, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
		super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
		this.id = id;
		this.deptId = deptId;
		this.tenantId = tenantId;
	}

	public boolean isAdmin() {

		return isAdmin(this.getId());
	}

	public static boolean isAdmin(Long userId) {
		return userId != null && 1L == userId;
	}
}
